<?php

class Add implements Action {

  private $name;
  private $bday;
  private $address;
  private $cellPhone;
  private $eMail;

  public function setParams($param = null) {
    $this->name = $_POST['name'];
    $this->bday = $_POST['birthdate'];
    $this->address = $_POST['address'];
    $this->cellPhone = $_POST['cellPhone'];
    $this->eMail = $_POST['eMail'];
  }

  public function validate($response) {
    if ($this->name == "") {
      $response->addError("Name missing");
    }
    if ($this->bday == "") {
      $response->addError("Birthday missing");
    }
    if ($this->address == "") {
      $response->addError("Address missing");
    }
    if ($this->cellPhone == "") {
      $response->addError("Cellphone missing");
    }
    if ($this->eMail == "") {
      $response->addError("Email missing");
    }
  }

  public function execute($response) {
    $con = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD) or die(mysql_error());
    mysql_select_db(DB_NAME, $con) or die(mysql_error());
    $sql = "INSERT INTO clients (name, bday, address, cellPhone, eMail, dateRegistered) 
            VALUES ('$this->name','$this->bday','$this->address','$this->cellPhone','$this->eMail', NOW())";
    mysql_query($sql, $con) or die(mysql_error());
  }

  public function getContentType() {
    return JSON;
  }

  public function getHTTPMethod() {
    return POST;
  }

}

?>
